#pragma once
#include "CBrush.h"

#include "CMILMatrix.h"
class HWTextureManager;
class CRenderTarget;
class SurfaceCache;
class CTiledSurface;
class HWTexture;


class CTileBrush :
	public CBrush
{
protected: 
	CTileBrush(CCoreServices * pCore);
protected: 
	virtual ~CTileBrush();
public: 
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual XUINT32 GetTypeIndex() const;
	virtual XINT32 NeedsBounds();
	virtual HRESULT InitInstance();
	virtual HRESULT CreateBrushSpan(const CMILMatrix * pWorldTransform, const struct XRECTF_WH * pBrushBounds, struct IBrushSpan * * ppBrushSpan);
	virtual XINT32 IsOpaque();
	virtual XINT32 HasClipRect();
	virtual HRESULT HitTestBrushClipInLocalSpace(const struct XRECTF_WH * pGeometryRenderBounds, const HitTestPolygon & target, XBOOL * pIsHit);
	virtual HRESULT HitTestBrushClipInLocalSpace(const struct XRECTF_WH * pGeometryRenderBounds, const struct XPOINTF & target, XBOOL * pIsHit);
	virtual HRESULT ComputeDeviceToSource(const CMILMatrix * pWorldTransform, const struct XRECTF_WH * pRenderBounds, CMILMatrix * pDeviceToSource, XBOOL bForRendering);
	static HRESULT ComputeStretchMatrix(const struct XRECTF_WH * pNaturalBounds, const struct XRECTF_WH * pRenderBounds, enum XcpBrushAlignmentX alignmentX, enum XcpBrushAlignmentY alignmentY, enum XcpBrushStretch stretch, CMILMatrix * pStretchMatrix);
	static HRESULT ComputeStretchAndAlignment(const struct XRECTF_WH * pNaturalBounds, const struct XRECTF_WH * pRenderBounds, enum XcpBrushAlignmentX alignmentX, enum XcpBrushAlignmentY alignmentY, enum XcpBrushStretch stretch, XFLOAT * pOffsetX, XFLOAT * pOffsetY, XFLOAT * pScaleX, XFLOAT * pScaleY);
	virtual struct IPALSurface * GetSurface();
	virtual void SetSurface(struct IPALSurface * pSurface);
	virtual HRESULT Lock(void * * ppAddress, XINT32 * pnStride, XUINT32 * puWidth, XUINT32 * puHeight);
	virtual XBOOL UnLock();
	virtual HRESULT EnsureAndUpdateHardwareResources(HWTextureManager * pTextureManager, CRenderTarget * pRenderTarget, SurfaceCache * pSurfaceCache);
	virtual XBOOL IsTiledSurface();
	virtual CTiledSurface * GetTiledSurfaceNoRef();
	void SetIsVideo(XINT32);
	XINT32 IsVideo();
	void SetYUVSurface(struct IPALSurface * pyuvSurface);
	void SetRGBSurface(struct IPALSurface * prgbSurface);
	virtual HWTexture * GetHardwareSurface();
	virtual HRESULT HandleLostResources(SurfaceCache * pSurfaceCache);
	virtual HRESULT ReloadSoftwareSurfaceIfReleased();
	virtual struct IPALSurface * GetSoftwareSurface();
	enum XcpBrushAlignmentX m_AlignmentX;
	enum XcpBrushAlignmentY m_AlignmentY;
	enum XcpBrushStretch m_Stretch;
	CMILMatrix m_matTileMode;
	XINT32 m_bIsVideo;
private: 
	XINT32 m_bIs709;
	XUINT32 m_nWidth;
	XUINT32 m_nHeight;
public: 
	virtual HRESULT D2DEnsureDeviceIndependentResources(const struct D2DPrecomputeParams & cp, const CMILMatrix * pMyAccumulatedTransform, const struct XRECTF_RB * pBrushBounds, struct AcceleratedBrushParams * pPALBrushParams);


};
